/**
 * Created by liuyun19 on 2018/12/26.
 * ﻿actions: 处理你要干什么，异步请求、判断和流程控制, 类似于mutation
 */
import request from '@/api';
import * as types from './mutations-types';

export default {
  //一个接口
  collectDonateCount({commit}) {
    request.collectDonateCount()
      .then(res => {
        console.log('actions: collect donate count---->', res);
        let err_code = res.code;
        let err_msg = res.message;
        if(err_code === 0) {
          commit(types.COLLECT_DONATE_COUNT, res.data)
        } else {
          commit(types.COLLECT_DONATE_COUNT_FAILE, {'err_code': err_code, 'err_msg': err_msg})
        }
      })
      .catch(err => {
        commit(types.COLLECT_DONATE_COUNT_FAILE, {'err_msg': err})
      })
  },
  // 又一个接口
  fetchProjectList({commit, state}, obj) {
    console.log('actions: fetch project 111111---->', state, obj);
    request.fetchProjectList(obj)
      .then(res => {
        let err_code = res.code;
        let err_msg = res.message;
        if(err_code === 0) {
          commit(types.FETCH_PROJECT_LIST, res.data)
        } else {
          commit(types.FETCH_PROJECT_LIST_FAILE, {'err_code': err_code, 'err_msg': err_msg})
        }
      })
      .catch(err => {
        commit(types.FETCH_PROJECT_LIST_FAILE, {'err_msg': err})
    })
  }
}
